<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
      <!--BEGIN TITLE & BREADCRUMB PAGE-->
      <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
          <div class="page-header pull-left">
              <div class="page-title">数据导出</div>
          </div>
          <ol class="breadcrumb page-breadcrumb pull-left">
              <li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i 
              		class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li>大数据仓储&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li class="active">数据导出</li>
          </ol>
           
          <div class="clearfix"></div>
      </div>
      <!--END TITLE & BREADCRUMB PAGE-->
      <!--BEGIN CONTENT-->
      <div class="page-content">
      
      <div class="row">
		      <div class="col-lg-12">
		       <div class="note note-danger">
		           <h3 class="box-heading">Tips</h3>
		           <p>
		           	管理员新建数据导出任务后，需进行提交操作，然后点击分布式任务调度菜单进心相关操作。
		           </p>
		       </div>
		   </div>
		</div>
      
      
      <div class="row mbl">
           <div class="col-lg-6">
               <div class="input-group input-group-sm mbs"><span class="input-group-btn">
               <select id="queryParams" class="btn btn-danger dropdown-toggle" style="width :140px;">
                     <option value="-1">筛选项&nbsp;<span class="caret"></span></option>
                    <option value="name">数据导出名称</option>
                    <option value="description">数据导出名称描述</option>
                    
                  <!--   <option value="fieldType">数据类型</option>--> 
                    </select>
                   </span>
                   <input type="text" id="text"  placeholder="请输入关键词..." class="form-control" /><span class="input-group-btn"><button type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="list1()">搜索</button></span>
               </div>
           </div>
           <div class="col-lg-6">
           <div class="tb-group-actions pull-right"><span>当前共<label id="pageSize"></label>条记录:</span>
                   <select id="pageNumber" class="table-group-action-input form-control input-inline input-small input-sm mlm" onchange="list1()">
                       <option value="5">5</option>
                       <option value="10" >10</option>
                       <option value="15" selected>15</option>
                       <option value="25">25</option>
                       <option value="50">50</option>
                   </select>&nbsp;
               <div class="tb-group-actions pull-right">
                <button class="btn btn-sm btn-primary" onclick="exportto('0')">新增
                   </button>
                   </div>
               </div>
           </div>
       </div>
 
      <table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
            <thead>
                <tr>                 
                    <th >序号</th>
                    <th >数据导入名称</th>
                    <th >数据导入描述</th>
                    <th >数据源名称</th>
                    <th >知识库名称</th>
                    <th >创建时间</th>
                    <th >提交时间</th>
                    <th >状态</th>
                    <th >可操作</th>
                </tr>
            </thead>
            <tbody id="newspaperls"></tbody>
        </table>
<div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
				<span class='subtitle' style="font-size: 15px;">数据为空!</span>
		</div>
        <div id="page1" style="text-align: center; margin-top: 20px;"></div>
    </div>
                     
    <!--END CONTENT-->
    </div>
<?} ?>
<script>
 var cur;
 var systemName="store";
$(function(){
    cur=1;
	list1(cur);
});
function get()
{
  list1(cur);
}

	function list1(curr) {
		$.getJSON("./DataHandlingList.do",
		{
			page : curr || 1,
			queryParams : $("#queryParams").val(),
			text : $("#text").val(),
			type : 1,
			pageNumber : $("#pageNumber").val()
		},
		function(res) {
			//此处仅仅是为了演示变化的内容
			var str = "";
			if (res.listsize > 0) {
				$("#dataNull").hide();
			} else {
				$("#dataNull").show();
			}
			$("#newspaperls").html("")
			for ( var i = 0; i < res.listsize; i++) {
				var dataSourcename = '';
				for ( var j = 0; j < res.rdataSource.length; j++) {
					if (res.rdataSource[j].id == res.result[i].dataSourceId
							&& dataSourcename == '') {
						dataSourcename = res.rdataSource[j].name;
					}
				}
				var classesname = '';
				for ( var j = 0; j < res.rclasses.length; j++) {
					if (res.rclasses[j].id == res.result[i].classesId
							&& classesname == '') {
						classesname = res.rclasses[j].nameZh;
					}
				}
				var statusname = "";
				if (res.result[i].status == 0) {
					statusname = "未提交";
				} else {
					statusname = "已提交";
				}

				// alert(statusname);
				str += "<tr><td align=\"center\"> "
						+ (i + 1)
						+ "</td><td> <label >"
						+ res.result[i].name
						+ "</label></td><td><label >"
						+ res.result[i].description
						+ "</label></td><td><label >"
						+ dataSourcename
						+ "</label></td><td><label >"
						+ classesname
						+ "</label></td><td><label >"
						+ res.result[i].createTime
						+ "</label></td><td><label >"
						+ res.result[i].submitTime
						+ "</label></td><td> <span class=\"label label-sm label-success\"> "
						+ statusname + "</span></td><td>";
				if (res.result[i].status == 0) {
					str += "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"subm('"
							+ res.result[i].id
							+ "')\">"
							+ "提交"
							+ "</button>";
				}
				if (null != res.result[i].downloadPath && '' != res.result[i].downloadPath) {
					str += "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"exportDynamicData('"
							+ res.result[i].id
							+ "')\">"
							+ "下载"
							+ "</button>";
				}
				str += "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"del('"
						+ res.result[i].id
						+ "')\">"
						+ "删除"
						+ "</button>" + "</td></tr>";
			}
			$("#newspaperls").append(str);
			document.getElementById('pageSize').innerHTML = res.listsize;
			laypage({
				cont : document.getElementById('page1'), //容器。值支持id名、原生dom对象，jquery对象,
				pages : res.pageSize, //总页数
				skip : true, //是否开启跳页
				skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
				curr : curr || 1,
				last : res.pageSize,
				groups : 6,//连续显示分页数
				jump : function(obj, first) { //触发分页后的回调
					if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
						list1(obj.curr);
						var curr = obj.curr;
						curr = obj.curr;
					}
				}
			});
		});
	}

	function moban() {
		layer.open({
			type : 2,
			icon : 1,
			title : "模版列表",
			skin : 'layer-ext-moon',
			area : [ '800px', '600px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '关闭' ],
			content : [ "data-import-templet-list.html", 'no' ],

			cancel : function(index) {
			}
		});
	}

	function download() {
		$.ajax({
			type : "post",
			url : "./DataImportTempletdownload.do",
			data : {},
			dataType : "json",
			success : function(data) {
				layer.msg("删除成功");
			},
			error : function(data) {
				alert("请求失败");
			}
		});

	}

	function exportto() {
		layer.open({
			type : 2,
			icon : 1,
			skin : 'layer-ext-moon',
			area : [ '830px', '650px' ],
			title : "添加数据导出",
			fix : false, //不固定
			scrollbar : true,
			shadeClose : true,
			move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "data-handling-export-to.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}

	function subm(id) {
		$.ajax({
			type : "post",
			url : "./DataHandlingHandle.do",
			data : {
				"id" : id
			},
			dataType : "json",
			success : function(data) {
				if (data.result == "ok") {
					layer.msg("提交成功");
					get();
				} else {
					layer.msg("提交失败");
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	function exportDynamicData(dataHandlingId){
	    var _downiframe = $("iframe#_downiframe");
		if (_downiframe.length == 0) {
			_downiframe =$("<iframe id='_downiframe' name='_downiframe' style='display:none'></iframe>").appendTo($("body"));
		}
		_downiframe.attr("src", "exportDataHandlingData.do?id="+dataHandlingId);
	} 
	function del(id) {
		layer.confirm("是否确认删除？", {
			btn : [ "确定", "删除" ]
		//按钮
		}, function() {
			$.ajax({
				type : "post",
				url : "./DataHandlingImportDel.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if (data.result == "ok") {
						layer.msg("删除成功！", {
							icon : 6
						});
					} else {
						layer.msg(data.msg, {
							icon : 5
						});
					}
					get();
				},
				error : function(data) {
					layer.msg("请求失败！", {
						icon : 2
					});
				}
			});

		}, function() {
		});
	}
</script>